<template>
  <div class="login">
    <h3 class="loginTitle">高质量数据集全周期工作台</h3>
    <el-form size="large" ref="ruleFormRef" :model="formData" :rules="rules" label-width="auto" class="elForm">
      <el-form-item label="用户名：" prop="user">
        <el-input v-model="formData.user" :suffix-icon="User" />
      </el-form-item>
      <el-form-item label="密码：" prop="password">
        <el-input v-model="formData.password" type="password" :suffix-icon="Hide" />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" class="LoginBtn" @click="handleLogin(ruleFormRef)">登录</el-button>
      </el-form-item>
      <el-form-item label=" ">
        <div class="registerAndForget">
          <span @click="handleRegister">注册</span>
          <span>忘记密码</span>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { User, Hide } from '@element-plus/icons-vue';
import { ref,reactive } from 'vue';
import { login } from '@/api/login';
import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox, FormInstance} from 'element-plus'

interface FormInterface {
  user: '',
  password: ''
};
const router = useRouter();
const poops = defineProps({
  isLogin:{
    type:Boolean,
    default:true
  }
})

const formData = reactive<FormInterface>({
  user: '',
  password: '',
});

const rules = reactive({
  user: [
    {
      required: true,
      message: '请输入用户名'
    },
  ],
  password: [
    {
      required: true,
      message: '请输入密码'
    },
  ]
})
const ruleFormRef = ref<FormInstance>();
// 登录
const handleLogin = (formEl) => {
  formEl.validate((valid, fields) => {
    if (valid) {
      login({}).then((res:any) => {
        sessionStorage.setItem('token',res.token);
        router.push('/score');
      })
    }
  })
}

// 注册
const emits = defineEmits(['update:isLogin']);
const handleRegister = () => {
  console.log(1)
  emits('update:isLogin', false);
}
</script>
<style scoped lang="scss">
  .login {
    border-radius: 8px;
    background-color: #092047;
    padding: 70px 150px 30px 140px;
    box-shadow: 10px 10px 10px #b1aec8;
    color: #fff;
    width: 650px;
    height: 450px;

    .loginTitle {
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--theme-color);
      font-size: 22px;
      margin-left: 45px;

      img {
        width: 50px;
        margin-right: 12px;
      }
    }

    .el-form {
      margin-top: 30px;
      margin-left: -30px;

      .el-form-item {
        ::v-deep .el-form-item__label {
          color: #fff !important;
          font-size: 16px;
        }

        ::v-deep .el-input__inner {
          width: 240px;
        }
      }
    }

    .LoginBtn {
      width: 294px;
      font-size: 18px;
      margin-top: 10px;
    }

    .registerAndForget {
      display: flex;
      justify-content: space-between;
      width: 100%;
      margin-top: -25px;
      padding-right: 10px;
      span {
        cursor: pointer;
      }
    }
  }
</style>